<?php

include_once 'ConditionStatement.php';
include_once 'StatementCollection.php';

/**
 * Represents an if...else statement
 * 
 * elseif is not supported
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic 
 * @example ../Classes/IfElseStatementExample.php
 */

class IfElseStatement extends ConditionStatement
{
    /**
     * The IfElseStatement constructor
     * 
     * Both $TrueStatements and $FalseStatements can be ommited by setting them to null
     * 
     * @param Expression $Condition The boolean expression to be evalueted true or false
     * @param StatementCollection $TrueStatements The statements in the if block
     * @param StatementCollection $FalseStatements The statements in the else block
     */
    
    public function __construct(Expression $Condition,
        StatementCollection $TrueStatements = null, 
        StatementCollection $FalseStatements = null)
    {
        parent::__construct();
        $this->set_Condition($Condition);
        
        $TrueStatements == null ? 
            $this->TrueStatements = new StatementCollection() : 
            $this->set_TrueStatements($TrueStatements);
        
        $FalseStatements == null ?
            $this->FalseStatements = new StatementCollection() :
            $this->set_FalseStatements($FalseStatements);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'TrueStatements')
        {
            $this->set_TrueStatements($value);
        }
        
        if($name == 'FalseStatements')
        {
            $this->set_FalseStatements($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'TrueStatements')
        {
            return $this->get_TrueStatements();
        }
        
        if($name == 'FalseStatements')
        {
            return $this->get_FalseStatements();
        }
    }
    
    /**
     * The $TrueStatements getter method
     * @return StatementCollection 
     */
    
    public function get_TrueStatements()
    {
        return $this->TrueStatements;
    }

    /**
     * The $TrueStatements setter method
     * @param StatementCollection $TrueStatements 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_TrueStatements(StatementCollection $TrueStatements)
    {
        $this->TrueStatements = $TrueStatements;
    }

    /**
     * The $FalseStatements getter method
     * @return StatementCollection 
     */
    
    public function get_FalseStatements()
    {
        return $this->FalseStatements;
    }

    /**
     * The $FalseStatements setter method
     * @param StatementCollection $FalseStatements 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error 
     */
    
    public function set_FalseStatements(StatementCollection $FalseStatements)
    {
        $this->FalseStatements = $FalseStatements;
    }

    /**
     * The statements in the if block
     * @var StatementCollection 
     */
    
    private $TrueStatements;
    
    /**
     * The statements in the else block
     * @var StatementCollection 
     */
    
    private $FalseStatements;
}

?>
